<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>toString</title>
</head>

<body>
    <script>
        function Person(name, age) {
            this.name = name;
            this.age = age;
        }

        Person.prototype.toString = function () {
            console.log(`name"${this.name} age: ${this.age}`)

        }
        /* 
        当我们直接在页面中打印一个对象时，事件上是输出的对象的toString()方法的返回值
			//如果我们希望在输出对象时不输出[object Object]，可以为对象添加一个toString()方法
        
        
        */

        var p1 = new Person("Jack", 12);
        console.log(p1);
    </script>
</body>

</html>